import 'package:flutter/material.dart';
import 'package:xws/utils/theme_util.dart';

/// toast 背景
class ToastBg extends StatelessWidget {
  const ToastBg({
    Key? key,
    required this.icon,
    required this.content,
    this.child,
    this.alignment,
    this.width,
    this.height,
    this.padding,
  }) : super(key: key);

  const ToastBg.success({
    this.icon = Icons.check_rounded,
    this.content = 'success',
    this.child,
    this.alignment = Alignment.center,
    this.width = 100,
    this.height = 100,
    this.padding,
  });

  const ToastBg.error({
    this.icon = Icons.report_gmailerrorred_rounded,
    this.content = 'error',
    this.child,
    this.alignment,
    this.width,
    this.height,
    this.padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
  });

  const ToastBg.info({
    this.icon = Icons.notifications_rounded,
    this.content = 'info',
    this.child,
    this.alignment,
    this.width,
    this.height,
    this.padding = const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
  });

  final IconData icon;

  final String content;

  final Widget? child;

  final AlignmentGeometry? alignment;

  final double? width;

  final double? height;

  final EdgeInsetsGeometry? padding;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      height: height,
      alignment: alignment,
      padding: padding,
      constraints: BoxConstraints(
        maxHeight: sh * 0.8,
        maxWidth: sw * 0.9,
      ),
      child: child ??
          Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Icon(icon, color: Colors.white, size: 50),
              const SizedBox(height: 8),
              Text(content,
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 15,
                  )),
            ],
          ),
      decoration: BoxDecoration(
        color: Colors.black.withOpacity(0.8),
        borderRadius: BorderRadius.circular(8),
      ),
    );
  }
}
